package edu.ccdb.irods.methods;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.ccdb.irods.signature.UploadStatus;

public class UploadToolFileStatus implements UploadStatus {

	private Map<String, BigInteger> listFile;
	private BigInteger totalBytesUploaded;
	private BigInteger totalSize; 
	
	public UploadToolFileStatus() {
		listFile = new HashMap<String, BigInteger>();
		
		totalBytesUploaded = new BigInteger("0");
	}
	
	public UploadToolFileStatus(List<String> files, BigInteger totalSize) {
		this();
	
		this.totalSize = totalSize;
		for (String element: files){
			listFile.put(element,new BigInteger("0") );
		}
	}
		
	public BigInteger getSingleFileStatus(String irodsPath) {

		return listFile.get( irodsPath );
	}

	public BigInteger getTotalUploadedBytes() {
		return totalBytesUploaded;
	}

	public int getTotatlUploadedPercent() {
		
		return totalBytesUploaded.multiply( new BigInteger("100")).divide(totalSize).intValue();		
	}

	public void setSingleFileStatus(String irodsPath, BigInteger uploadedBytes) {
		
		if (listFile.containsKey(irodsPath))
			listFile.put(irodsPath, ( listFile.get( irodsPath).add( uploadedBytes) )  );
		else 
			listFile.put(irodsPath,  ( uploadedBytes )  );
		
		totalBytesUploaded = totalBytesUploaded.add( uploadedBytes );
	}

}
